package com.liy.cloud.common.feign.fallback;

import com.das.framework.common.vo.PageVO;
import com.liy.cloud.common.feign.api.BaseFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.das.framework.common.extvo.ResultVO;

import feign.hystrix.FallbackFactory;

/**
 * 熔断处理:
 * 该处理方式可 查看到失败的异常信息，推荐使用该工厂方式
 */
@Component
public class BaseFeignClientFallbackFactory implements FallbackFactory<BaseFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(BaseFeignClientFallbackFactory.class);

    @Override
    public BaseFeignClient create(Throwable e) {

        log.info("base feign fallback; reason was: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return new BaseFeignClient() {

            @Override
            public ResultVO getTypeParamInfo() {
                return new ResultVO(false, "查询设备种类参数信息数据异常: " + e.getMessage(), "500");
            }

            @Override
            public ResultVO getEquidGroup() {
                return new ResultVO(false, "查询参数内容数据异常: " + e.getMessage(), "500");
            }

            @Override
            public PageVO queryEquparamAll(Object vo, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("查询设备参数数据异常: " + e.getMessage());
                return pageVO;
            }

            @Override
            public PageVO queryCardTypeAll(Object obj, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("查询卡类型数据异常: " + e.getMessage());
                return pageVO;
            }

            @Override
            public PageVO queryLineAll(Object vo, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("查询线路数据异常: " + e.getMessage());
                return pageVO;
            }

        };
    }

}
